//
//  JoinSiftViewController.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/2.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "JoinSiftViewController.h"
#import "CheckListViewController.h"
@interface JoinSiftViewController ()<UITextFieldDelegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)UIView * topView;
@property (nonatomic, strong)UIView * middleView;
@property (nonatomic, strong)UIView * bottomView;
@property (nonatomic, strong)UIView * bottomMoneyView;//底部栏
@property (nonatomic, strong)UILabel * payMoneyLab;//支付金额

@property (nonatomic, strong)UILabel * subTitleLab;//副标题
@property (nonatomic, strong)UILabel * predictProfitLab;//预计收益
@property (nonatomic, strong)UITextField * specificMoneyLab;//具体数额
@property (nonatomic, strong)UILabel * suggestLab;//平台建议
@property (nonatomic, strong)UILabel * produceContentLab;//产品名称标题
@property (nonatomic, strong)UILabel * bidDeadlineContentLab;//投标期限
@property (nonatomic, strong)UILabel * predictExpireContentLab;//预计到期
@property (nonatomic, strong)UILabel * interestWayContentLab;//计息方式
@property (nonatomic, strong)UILabel * dueProcessContentLab;//到期处理
@property (nonatomic, assign)int lendContentMoney;//出借金额
@property (nonatomic, assign)float lendProfitRateDou;//出借百分比
//@property (nonatomic, strong)NSString * lendRateStr;//出借百分比
@property (nonatomic, assign)float lendProfitContent;//出借终收益
@property (nonatomic, assign)int lendMaxMoney;//出借最高金额
@property (nonatomic, assign)int lendDays;//投资期限，投资时长
@property (nonatomic, strong)UIButton * payBtn;//支付按钮
@end

@implementation JoinSiftViewController (networking)
//投标详细信息
- (void)joinSiftDetailData{
    [self showprogressHUD];
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{
                           @"userName":[UserModel sharedInstanced].mobile,
                           @"blessingsid":self.bidID,
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"userName":[UserModel sharedInstanced].mobile,
                               @"blessingsid":self.bidID,
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/homepage/index?api=api1014"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            if ([jsonData[@"code"] isEqualToString:@"000000"]) {
                if ([jsonData[@"body"] count] > 0) {
                    if ([compareMD5Str isEqualToString:signResult]) {
                        NSLog(@"成功");
                        NSDictionary * contentDic = jsonData[@"body"][0];
                        self.subTitleLab.text = [NSString stringWithFormat:@"%@元起投，%@元的倍数递增", contentDic[@"invam"], contentDic[@"invam"]];
                        self.predictProfitLab.text = [NSString stringWithFormat:@"预计到期收益%@元", contentDic[@"earnings"]];
                        self.specificMoneyLab.text = [NSString stringWithFormat:@"%@", contentDic[@"invam"]];//具体钱数
                        self.payMoneyLab.text = [NSString stringWithFormat:@"确认支付金额 %@", contentDic[@"invam"]];
                        self.suggestLab.text = [NSString stringWithFormat:@"平台建议年均出借率%@%%", contentDic[@"lolimit"]];
                        self.produceContentLab.text = contentDic[@"entitle"];//产品名称
                        self.bidDeadlineContentLab.text = [NSString stringWithFormat:@"%@天", contentDic[@"invtime"]];;//投标期限
                        self.predictExpireContentLab.text = contentDic[@"proEndTime"];//预计到期时间
                        self.dueProcessContentLab.text = contentDic[@"huankuan"];//到期处理方式
                        //整数型，出借金额，进行运算，也是以倍数增长来投资
                        self.lendContentMoney = [contentDic[@"invam"] intValue];
                        //float，出借率，进行运算
                        self.lendProfitRateDou = [contentDic[@"lolimit"] floatValue];
                        //整数型，出借最高金额
                        self.lendMaxMoney = [contentDic[@"sursum"] intValue];
                        //整数型，投资期限，投资天数
                        self.lendDays = [contentDic[@"invtime"] intValue];
                    }else{
                        NSLog(@"失败");
                    }
                }else{
                    ShowMessage(jsonData[@"msg"]);
                }
            }else{
                ShowMessage(jsonData[@"msg"]);
            }
        }
    }];
}

@end
@implementation JoinSiftViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStatusBarBackgroundColor:[UIColor whiteColor]];
    self.navigationItem.title = @"加入福乐精选";
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //返回按钮
    UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, 14/WIDTH_6_SCALE + 24 + 20, 24/WIDTH_6_SCALE, 30/WIDTH_6_SCALE)];
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"out"] forState:UIControlStateNormal];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.view.backgroundColor = [UIColor whiteColor];
    //页面标题
    
    [self setUpViews];//搭建控件
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomMoneyView];
    
//    [self joinSiftDetailData];//网络接口x
//    self.lendContentMoney = 1;
}
#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVI_HEIGHT - BOTTOM_HEIGHT - 50/WIDTH_6_SCALE) style:UITableViewStylePlain];
        _tableView.backgroundColor = getColor(grayBGColor);
        _tableView.tableHeaderView = self.headerView;
    }return _tableView;
}

- (void)setUpViews{
    _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVI_HEIGHT - BOTTOM_HEIGHT)];
    _headerView.backgroundColor = getColor(grayBGColor);
    [_headerView addSubview:self.topView];
    [_headerView addSubview:self.middleView];
    [_headerView addSubview:self.bottomView];
}

//上部
- (UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 190/WIDTH_6_SCALE)];
        _topView.backgroundColor = [UIColor whiteColor];
        //标题
        UILabel * titleLab = [[UILabel alloc] init];
        [self label:titleLab withFont:DEF_FontSize_14 withText:@"出借金额(元)" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_topView];
        //副标题
        UILabel * subTitleLab = [[UILabel alloc] init];
        [self label:subTitleLab withFont:DEF_FontSize_10 withText:@"1000万元起投，10000元的倍数递增" withTextColor:getColor(@"959595") withTextAlignment:NSTextAlignmentLeft withView:_topView];
        self.subTitleLab = subTitleLab;
        //圆角长方形
        UIImageView * longView = [[UIImageView alloc] init];
        longView.image = [UIImage imageNamed:@"circleLongView"];
        [_topView addSubview:longView];
        //预计收益
        UILabel * predictProfitLab = [[UILabel alloc] init];
        [self label:predictProfitLab withFont:DEF_FontSize_12 withText:@"预计到期收益200.5元" withTextColor:getColor(@"959595") withTextAlignment:NSTextAlignmentCenter withView:_topView];
        self.predictProfitLab = predictProfitLab;
        //减号
        UIButton * minusBtn = [[UIButton alloc] init];
        [minusBtn addTarget:self action:@selector(minusBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self button:minusBtn withBGColor:[UIColor orangeColor] withLayerBorderColor:[UIColor orangeColor] withLayerBorderWith:1 withCornerRadius:4 withMasksToBounds:YES withViwe:_topView];
        [minusBtn setBackgroundImage:[UIImage imageNamed:@"-"] forState:UIControlStateNormal];
        //加号
        UIButton * plusBtn = [[UIButton alloc] init];
        [plusBtn addTarget:self action:@selector(plusBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self button:plusBtn withBGColor:[UIColor orangeColor] withLayerBorderColor:[UIColor orangeColor] withLayerBorderWith:1 withCornerRadius:4 withMasksToBounds:YES withViwe:_topView];
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];

        //具体数额
        UITextField * specificMoneyLab = [[UITextField alloc] init];
        specificMoneyLab.font = [UIFont systemFontOfSize:30];
        specificMoneyLab.textColor = getColor(@"ff4433");
        specificMoneyLab.textAlignment = NSTextAlignmentCenter;
        specificMoneyLab.delegate = self;
        specificMoneyLab.text = @"0";
        [_topView addSubview:specificMoneyLab];
        self.specificMoneyLab = specificMoneyLab;
        [self.specificMoneyLab addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

        //金额下横线
        UIView * moneyLineView = [[UIView alloc] init];
        moneyLineView.backgroundColor = getColor(@"bdbdbd");
        [_topView addSubview:moneyLineView];
        //平台建议
        UILabel * suggestLab = [[UILabel alloc] init];
        [self label:suggestLab withFont:DEF_FontSize_10 withText:@"平台建议年均出借率10.0%" withTextColor:getColor(@"bdbdbd") withTextAlignment:NSTextAlignmentCenter withView:_topView];
        self.suggestLab = suggestLab;
        //masonry
        __weak typeof (self)weakSelf = self;
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.topView.mas_left).mas_offset(17.5/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.topView.mas_top).mas_offset(16/WIDTH_6_SCALE);
            make.height.mas_offset(13.5/WIDTH_6_SCALE);
        }];
        [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.topView.mas_left).mas_offset(18/WIDTH_6_SCALE);
            make.height.mas_offset(10.5/WIDTH_6_SCALE);
            make.top.equalTo(titleLab.mas_bottom).mas_offset(8/WIDTH_6_SCALE);
        }];
        [predictProfitLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.subTitleLab.mas_bottom).mas_offset(16/WIDTH_6_SCALE);
            make.centerX.equalTo(weakSelf.topView.mas_centerX);
            make.height.mas_offset(25/WIDTH_6_SCALE);
        }];
        [longView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(predictProfitLab.mas_centerX);
            make.width.equalTo(predictProfitLab.mas_width).mas_offset(44/WIDTH_6_SCALE);
            make.top.equalTo(self.subTitleLab.mas_bottom).mas_offset(16/WIDTH_6_SCALE);
//            make.bottom.equalTo(predictProfitLab.mas_bottom).mas_offset(15/WIDTH_6_SCALE);
            make.height.mas_offset(35/WIDTH_6_SCALE);
        }];
        [minusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.topView.mas_left).mas_offset(44/WIDTH_6_SCALE);
            make.top.equalTo(predictProfitLab.mas_bottom).mas_offset(5/WIDTH_6_SCALE);
            make.width.height.mas_offset(30/WIDTH_6_SCALE);
        }];
        [plusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.topView.mas_right).mas_offset(-44/WIDTH_6_SCALE);
            make.top.width.height.equalTo(minusBtn);
        }];
        [specificMoneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(predictProfitLab.mas_bottom).mas_offset(8/WIDTH_6_SCALE);
            make.height.mas_equalTo(25/WIDTH_6_SCALE);
            make.width.equalTo(moneyLineView.mas_width);
            make.centerX.equalTo(weakSelf.topView.mas_centerX);
        }];
        [moneyLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(minusBtn.mas_bottom).mas_equalTo(9/WIDTH_6_SCALE);
            make.height.mas_equalTo(1/WIDTH_6_SCALE);
            make.left.equalTo(minusBtn.mas_right).mas_equalTo(13/WIDTH_6_SCALE);
            make.right.equalTo(plusBtn.mas_left).mas_equalTo(-13/WIDTH_6_SCALE);
        }];
        [suggestLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(moneyLineView.mas_bottom).mas_equalTo(15/WIDTH_6_SCALE);
            make.centerX.equalTo(weakSelf.topView.mas_centerX);
            make.height.mas_equalTo(12/WIDTH_6_SCALE);
        }];
    }return _topView;
}
- (UIView *)middleView{
    if (!_middleView) {
        _middleView = [[UIView alloc] initWithFrame:CGRectMake(0, self.topView.bottom, SCREEN_WIDTH, 14/WIDTH_6_SCALE)];
        _middleView.backgroundColor = getColor(grayBGColor);
        //分割线
        UIView * topLineView = [[UIView alloc] init];
        topLineView.backgroundColor = getColor(grayColor);
        [_middleView addSubview:topLineView];
        UIView * bottomLineView = [[UIView alloc] init];
        bottomLineView.backgroundColor = getColor(grayColor);
        [_middleView addSubview:bottomLineView];
        __weak typeof (self)weakSelf = self;
        [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.middleView.mas_top);
            make.height.mas_equalTo(1/WIDTH_6_SCALE);
            make.left.right.equalTo(weakSelf.middleView);
        }];
        [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.middleView.mas_bottom).mas_offset(-1/WIDTH_6_SCALE);
            make.height.mas_equalTo(1/WIDTH_6_SCALE);
            make.left.right.equalTo(weakSelf.middleView);
        }];
    }return _middleView;
}
- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.middleView.bottom, SCREEN_WIDTH, 189/WIDTH_6_SCALE)];
        _bottomView.backgroundColor = [UIColor whiteColor];
        //产品名称标题
        UILabel * produceTitleLab = [[UILabel alloc] init];
        [self label:produceTitleLab withFont:DEF_FontSize_12 withText:@"产品名称" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        //产品名称
        UILabel * produceContentLab = [[UILabel alloc] init];
        self.produceContentLab = produceContentLab;
        [self label:self.produceContentLab withFont:DEF_FontSize_12 withText:@"公共WIFI二年062142" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        
        //投标期限标题
        UILabel * bidDeadlineTitleLab = [[UILabel alloc] init];
        [self label:bidDeadlineTitleLab withFont:DEF_FontSize_12 withText:@"投标期限" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        //投标期限
        UILabel * bidDeadlineContentLab = [[UILabel alloc] init];
        [self label:bidDeadlineContentLab withFont:DEF_FontSize_12 withText:@"365天" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        self.bidDeadlineContentLab = bidDeadlineContentLab;
        //预计到期标题
        UILabel * predictExpireTitleLab = [[UILabel alloc] init];
        [self label:predictExpireTitleLab withFont:DEF_FontSize_12 withText:@"预计到期" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        //预计到期
        UILabel * predictExpireContentLab = [[UILabel alloc] init];
        [self label:predictExpireContentLab withFont:DEF_FontSize_12 withText:@"2018年9月24日" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        self.predictExpireContentLab = predictExpireContentLab;
        //计息方式标题
        UILabel * interestWayTitleLab = [[UILabel alloc] init];
        [self label:interestWayTitleLab withFont:DEF_FontSize_12 withText:@"计息方式" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        //计息方式
        UILabel * interestWayContentLab = [[UILabel alloc] init];
        [self label:interestWayContentLab withFont:DEF_FontSize_12 withText:@"T+1" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        self.interestWayContentLab = interestWayContentLab;
        //到期处理标题
        UILabel * dueProcessTitleLab = [[UILabel alloc] init];
        [self label:dueProcessTitleLab withFont:DEF_FontSize_12 withText:@"到期处理" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        //到期处理
        UILabel * dueProcessContentLab = [[UILabel alloc] init];
        [self label:dueProcessContentLab withFont:DEF_FontSize_12 withText:@"到期赎回" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        self.dueProcessContentLab = dueProcessContentLab;
        //分割线
        UIView * bottomLineView = [[UIView alloc] init];
        bottomLineView.backgroundColor = getColor(grayColor);
        [_bottomView addSubview:bottomLineView];
        //对号框
        UIButton * checkBtn = [[UIButton alloc] init];
        [checkBtn setBackgroundColor:[UIColor orangeColor]];
        checkBtn.hidden = YES;
        [_bottomView addSubview:checkBtn];
        //我已阅读
        UILabel * haveReadTitleLab = [[UILabel alloc] init];
        haveReadTitleLab.hidden = YES;
        [self label:haveReadTitleLab withFont:DEF_FontSize_10 withText:@"我已阅读并同意" withTextColor:getColor(@"bdbdbd") withTextAlignment:NSTextAlignmentLeft withView:_bottomView];
        //福乐猪交易协议
        UIButton * agreementBtn = [[UIButton alloc] init];
        agreementBtn.hidden = YES;
        [_bottomView addSubview:agreementBtn];
        agreementBtn.titleLabel.font = DEF_FontSize_10;
        [agreementBtn setTitle:@"《福乐猪交易协议书》" forState:UIControlStateNormal];
        [agreementBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //masonry
        __weak typeof (self)weakSelf = self;
        [produceTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(18/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.bottomView.mas_top).mas_offset(22/WIDTH_6_SCALE);
            make.height.mas_offset(12/WIDTH_6_SCALE);
//            make.width.mas_offset(55/WIDTH_6_SCALE);
        }];
        [self.produceContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(produceTitleLab.mas_right).mas_offset(16/WIDTH_6_SCALE);
            make.top.height.equalTo(produceTitleLab);
            make.right.equalTo(weakSelf.bottomView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
        }];
        [bidDeadlineTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(produceTitleLab.mas_bottom).mas_offset(22/WIDTH_6_SCALE);
            make.left.height.width.equalTo(produceTitleLab);
        }];
        [bidDeadlineContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bidDeadlineTitleLab);
            make.left.height.right.equalTo(produceContentLab);
        }];
        [predictExpireTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.height.width.equalTo(bidDeadlineTitleLab);
            make.top.equalTo(bidDeadlineTitleLab.mas_bottom).mas_offset(22/WIDTH_6_SCALE);
        }];
        [predictExpireContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(predictExpireTitleLab);
            make.left.equalTo(bidDeadlineContentLab);
        }];
        [interestWayTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(predictExpireTitleLab.mas_bottom).mas_offset(22/WIDTH_6_SCALE);
            make.left.height.width.equalTo(predictExpireTitleLab);
        }];
        [interestWayContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(interestWayTitleLab);
            make.left.equalTo(predictExpireContentLab);
        }];
        [dueProcessTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(interestWayTitleLab.mas_bottom).mas_offset(22/WIDTH_6_SCALE);
            make.left.height.width.equalTo(interestWayTitleLab);
        }];
        [dueProcessContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(dueProcessTitleLab);
            make.left.equalTo(interestWayContentLab);
        }];
        [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.bottomView.mas_bottom).mas_offset(-1/WIDTH_6_SCALE);
            make.height.mas_offset(1/WIDTH_6_SCALE);
            make.left.right.equalTo(weakSelf.bottomView);
        }];
        [checkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bottomLineView.mas_bottom).mas_offset(14/WIDTH_6_SCALE);
            make.left.equalTo(weakSelf.bottomView.mas_left).mas_offset(18/WIDTH_6_SCALE);
            make.width.height.mas_offset(20/WIDTH_6_SCALE);
        }];
        [haveReadTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(checkBtn.mas_right).mas_offset(6/WIDTH_6_SCALE);
            make.centerY.equalTo(checkBtn.mas_centerY);
            make.width.mas_offset(85/WIDTH_6_SCALE);
        }];
        [agreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(haveReadTitleLab.mas_right).mas_offset(2/WIDTH_6_SCALE);
            make.centerY.equalTo(haveReadTitleLab.mas_centerY);
            make.height.mas_offset(13/WIDTH_6_SCALE);
        }];
    }return _bottomView;
}
- (UIView *)bottomMoneyView{
    if (!_bottomMoneyView) {
        _bottomMoneyView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 50/WIDTH_6_SCALE - NAVI_HEIGHT - BOTTOM_HEIGHT, SCREEN_WIDTH, 50/WIDTH_6_SCALE)];
        _bottomMoneyView.backgroundColor = [UIColor whiteColor];
        //分割线
        UIView * lineView = [[UIView alloc] init];
        lineView.backgroundColor = getColor(grayColor);
        [_bottomMoneyView addSubview:lineView];
        //支付金额
        self.payMoneyLab = [[UILabel alloc] init];
        self.payMoneyLab.backgroundColor = [UIColor whiteColor];
        [self label:self.payMoneyLab withFont:DEF_FontSize_12 withText:@"确认支付金额 10000" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentCenter withView:_bottomMoneyView];
        //支付按钮
        UIButton * payBtn = [[UIButton alloc] init];
        [payBtn setTitle:@"去下单" forState:UIControlStateNormal];
        [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [payBtn setBackgroundColor:[UIColor orangeColor]];
        payBtn.titleLabel.font = DEF_FontSize_12;
        [_bottomMoneyView addSubview:payBtn];
        self.payBtn = payBtn;
        [self.payBtn addTarget:self action:@selector(payBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        //masorny
        __weak typeof (self)weakSelf = self;
        [self.payMoneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.bottomMoneyView.mas_left);
            make.top.bottom.equalTo(weakSelf.bottomMoneyView);
            make.width.mas_offset(247/WIDTH_6_SCALE);
        }];
        [payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.payMoneyLab.mas_right);
            make.top.bottom.equalTo(weakSelf.bottomMoneyView);
            make.right.equalTo(weakSelf.bottomMoneyView);
        }];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(weakSelf.bottomMoneyView);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
    }return _bottomMoneyView;
}
#pragma mark - action
- (void)backBtnClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)minusBtnClick:(UIButton *)sender{
    NSLog(@"减");
//    self.lendContentMoney的数额为基数
    int contentMoneyInt = [self.specificMoneyLab.text intValue];//输入框内的金额
    int tempContentMoneyInt = contentMoneyInt - self.lendContentMoney;//点击一下之后应显示的金额
    if (tempContentMoneyInt < self.lendContentMoney) {
        self.specificMoneyLab.text = [NSString stringWithFormat:@"%i", self.lendContentMoney];//因为小于最低投资额，所以不允许再触发减法
        self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor grayColor]];
//        NSLog(@"%i", self.lendContentMoney);
        return;
    }
    self.specificMoneyLab.text = [NSString stringWithFormat:@"%i", tempContentMoneyInt];//输入框做减法之后的内容
    //当不是整数倍的时候进行提示
    if (tempContentMoneyInt % self.lendContentMoney != 0) {
        self.predictProfitLab.text = [NSString stringWithFormat:@"出借额必须是%i的整数倍", self.lendContentMoney];
        self.predictProfitLab.textColor = [UIColor redColor];
        self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor grayColor]];
    }else if (tempContentMoneyInt > self.lendMaxMoney){
        self.predictProfitLab.text = [NSString stringWithFormat:@"出借额不能大于%i", self.lendMaxMoney];
        self.predictProfitLab.textColor = [UIColor redColor];
        self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor grayColor]];
    }else{
        float contenMoneyF = tempContentMoneyInt * (self.lendProfitRateDou/100) / 365 * self.lendDays;
        self.predictProfitLab.text = [NSString stringWithFormat:@"预计到期收益%.2f元", contenMoneyF];//填所算的数值
        self.predictProfitLab.textColor = getColor(@"959595");
        self.payBtn.userInteractionEnabled = YES;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor orangeColor]];
    }
    self.payMoneyLab.text = [NSString stringWithFormat:@"确认支付金额 %i", tempContentMoneyInt];//支付
}
- (void)plusBtnClick:(UIButton *)sender{
    NSLog(@"加");
    int contentMoneyInt = [self.specificMoneyLab.text intValue];//输入框内的金额
    int tempContentMoneyInt = contentMoneyInt + self.lendContentMoney;//点击一下之后应显示的金额
    self.specificMoneyLab.text = [NSString stringWithFormat:@"%i", tempContentMoneyInt];//输入框做加法之后的内容
    //当不是整数倍的时候进行提示
    if (tempContentMoneyInt % self.lendContentMoney != 0) {
        self.predictProfitLab.text = [NSString stringWithFormat:@"出借额必须是%i的整数倍", self.lendContentMoney];
        self.predictProfitLab.textColor = [UIColor redColor];
        self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor grayColor]];
    }else if (tempContentMoneyInt > self.lendMaxMoney){
        self.predictProfitLab.text = [NSString stringWithFormat:@"出借额不能大于%i", self.lendMaxMoney];
        self.predictProfitLab.textColor = [UIColor redColor];
        self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor grayColor]];
    }else{
        float contenMoneyF = tempContentMoneyInt * (self.lendProfitRateDou/100) / 365 * self.lendDays;
        self.predictProfitLab.text = [NSString stringWithFormat:@"预计到期收益%.2f元", contenMoneyF];//填所算的数值
        self.predictProfitLab.textColor = getColor(@"959595");
        self.payBtn.userInteractionEnabled = YES;//支付按钮不允许按
        [self.payBtn setBackgroundColor:[UIColor orangeColor]];
    }
    self.payMoneyLab.text = [NSString stringWithFormat:@"确认支付金额 %i", tempContentMoneyInt];//支付
}
- (void)payBtnClick:(UIButton *)sender{
    NSLog(@"去下单");
    CheckListViewController * vc = [[CheckListViewController alloc] init];
    vc.bidID = self.bidID;
    vc.moneyNum = self.specificMoneyLab.text;
    vc.lendRate = self.lendProfitRateDou;
    vc.produceName = self.produceContentLab.text;
    vc.bidLimit = self.bidDeadlineContentLab.text;
    vc.endData = self.predictExpireContentLab.text;
    vc.profitWay = self.interestWayContentLab.text;
    vc.endDealWay = self.dueProcessContentLab.text;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)textFieldDidChange :(UITextField *)theTextField{
    if (self.specificMoneyLab) {
        //NO为全数字
        if ([self deptNumInputShouldNumber]) {
            NSLog(@"存在字母");
            self.predictProfitLab.text = [NSString stringWithFormat:@"%@", @"请输入数字"];
            self.predictProfitLab.textColor = [UIColor redColor];
            self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
            [self.payBtn setBackgroundColor:[UIColor grayColor]];
            return;
        }
        int contentMoneyInt = [self.specificMoneyLab.text intValue];//输入框内的金额
        if (contentMoneyInt % self.lendContentMoney != 0) {
            self.predictProfitLab.text = [NSString stringWithFormat:@"出借额必须是%i的整数倍", self.lendContentMoney];
            self.predictProfitLab.textColor = [UIColor redColor];
            self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
            [self.payBtn setBackgroundColor:[UIColor grayColor]];
        }else if (contentMoneyInt > self.lendMaxMoney){
            self.predictProfitLab.text = [NSString stringWithFormat:@"出借额不能大于%i", self.lendMaxMoney];
            self.predictProfitLab.textColor = [UIColor redColor];
            self.payBtn.userInteractionEnabled = NO;//支付按钮不允许按
            [self.payBtn setBackgroundColor:[UIColor grayColor]];
        }else{
            float contenMoneyF = contentMoneyInt * (self.lendProfitRateDou/100) / 365 * self.lendDays;
            self.predictProfitLab.text = [NSString stringWithFormat:@"预计到期收益%.2f元", contenMoneyF];//填所算的数值
            self.predictProfitLab.textColor = getColor(@"959595");
            self.payBtn.userInteractionEnabled = YES;//支付按钮不允许按
            [self.payBtn setBackgroundColor:[UIColor orangeColor]];
        }
    }
}
//判断是否存在字母
- (BOOL)deptNumInputShouldNumber{
    NSString *regex =@"[0-9]*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    if (![pred evaluateWithObject:self.specificMoneyLab.text]) {
        return YES;
    }return NO;
}


@end
